#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# This module consists of bit manipulation methods.

def maxbit(n):
    i = 0
    twoExpI = 1
    while twoExpI <= n:
        i += 1
        twoExpI <<= 1
    return i


def bitsWithoutLeadingBit(n):
    if (n == 0):
        yield 0
    else:
        i = maxbit(n) - 2
        while i >= 0:
            yield ithbit(i, n)
            i -= 1

def ithbit(i, n):
    if (1 << i) & n > 0:
        return 1
    return 0


